﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LumenWorks.Framework.IO.Csv;
using System.IO;
using System.Globalization;
using System.Data;

namespace Utilities
{
    public class StringUtil
    {
        public static string getTime()
        {
            return DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
        }

        public static float parseString2Float(string inputStr)
        {
            string strReturn = "";
            strReturn = inputStr.Remove(0, 1);
            return float.Parse(strReturn);
        }

        public static string[] buildArrayElement(string strElementsInString, string strOldSeperator, string strNewSeperator)
        {
            strElementsInString = strElementsInString.Trim();
            strElementsInString = strElementsInString.Replace(strOldSeperator, strNewSeperator);
            char[] arrayChar = strNewSeperator.ToCharArray();
            string[] arrayElement = strElementsInString.Split(arrayChar[0]);
            return arrayElement;
        }

        private static Boolean applicableURL(string url)
        {
            if (url.Length > 0 && url != null)
            {
                int length = url.Length;
                string lastChar = url[length - 1].ToString();
                if (lastChar.Equals("/"))
                    return true;
                else
                    return false;
            }
            return false;
        }

        public static string makeApplicableUrl(string url)
        {
            //Verify if having pages/logon.jsp at the end. If yes, remove it
            try
            {
                url = url.Replace("pages/logon.jsp", "");
            }
            catch { }

            if (applicableURL(url))
                return url;
            else
                return url + "/";
        }

        public static string getNow_HH_MM_SS_DD_MMM_YYYY()
        {
            string strDD = DateTime.Now.Day.ToString();
            if (strDD != null & strDD.Length == 1)
                strDD = "0" + strDD;
            string strMMM = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(DateTime.Now.Month);
            if (strMMM != null && strMMM.Length > 3) strMMM = strMMM.Remove(3);
            string strYYYY = DateTime.Now.Year.ToString();
            string strReturn = DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + "AM" + strDD + strMMM + strYYYY;
            return strReturn;
        }

    }
}